<?php
namespace app\admin\controller;

use app\admin\model\Goods;
use app\admin\model\GoodsOrder;
use app\admin\model\ListContent;
use app\admin\model\Questionnaire;
use app\admin\model\SassGoods;
use app\admin\model\TotalNum;
use think\Request;

class Index extends Base
{
    protected function _initialize(){
        $this->checkLogin();
        $this->menuLoad();
    }

    public function index(Request $request)
    {
        $totalNum = new TotalNum();
        if($request->post()){
            //用户
            $user = new \app\admin\model\User();
            $array['user'] = $user->totalNum();
            $userWhere['identity'] = 0;
            $array['user_a'] = $user->totalNumWhere($userWhere);
            $userWhere['identity'] = 1;
            $array['user_b'] = $user->totalNumWhere($userWhere);
            $userWhere['identity'] = 2;
            $array['user_c'] = $user->totalNumWhere($userWhere);

            //需求
            $demand = new \app\admin\model\Demand();
            $array['demand'] = $demand->totalNum();
            $demandWhere['status'] = 1;
            $array['demand_a'] = $demand->totalNumWhere($demandWhere);
            $demandWhere['status'] = 0;
            $array['demand_b'] = $demand->totalNumWhere($demandWhere);
            $demandWhere['status'] = 2;
            $array['demand_c'] = $demand->totalNumWhere($demandWhere);

            //酒店
            $selected = new ListContent();
            $selectedWhere['status'] = 1;
            $array['hotel'] = $selected->totalNum();
            $selectedWhere['city_id'] = 1;
            $array['hotel_a'] = $selected->totalNumWhere($selectedWhere);
            $selectedWhere['city_id'] = 21;
            $array['hotel_b'] = $selected->totalNumWhere($selectedWhere);

            //视频
            $foreknowledge = new \app\admin\model\Foreknowledge();
            $array['video_a'] = $foreknowledge->totalNum();
            $recorded = new \app\admin\model\Recorded();
            $array['video_b'] = $recorded->totalNum();
            $largerActive = new \app\admin\model\LargerActive();
            $array['video_c'] = $largerActive->totalNum();
            $array['video'] = $array['video_a'] + $array['video_b'] + $array['video_c'];

            //问卷
            $questionnaire = new Questionnaire();
            $array['questionnaire'] = $questionnaire->totalNum();
            //'1：银行；2：投资融资；3：证券；4：保险；5：信托；6：律师；7：财务；',
            $questionnaireWhere['type'] = 1;
            $array['questionnaire_a'] = $questionnaire->totalNumWhere($questionnaireWhere);
            $questionnaireWhere['type'] = 7;
            $array['questionnaire_b'] = $questionnaire->totalNumWhere($questionnaireWhere);
            $questionnaireWhere['type'] = 6;
            $array['questionnaire_c'] = $questionnaire->totalNumWhere($questionnaireWhere);

            //产品
            $goods = new SassGoods();
            $array['goods'] = $goods->totalNum();
            $goodsOrder = new GoodsOrder();
            $goodsOrderWhere['status'] = ['eq',3];
            $array['goods_a'] = $goodsOrder->totalNumWhere($goodsOrderWhere);
            $goodsOrderWhere['status'] = ['neq',3];
            $array['goods_b'] = $goodsOrder->totalNumWhere($goodsOrderWhere);

            //活动订单
            $activeOrder = new \app\admin\model\ActiveOrder();
            $array['active'] = $activeOrder->totalNum();
            $activeOrderWhere['status'] = ['eq',2];
            $array['active_a'] = $activeOrder->totalNumWhere($activeOrderWhere);
            $activeOrderWhere['status'] = ['neq',2];
            $array['active_b'] = $activeOrder->totalNumWhere($activeOrderWhere);

            $editWhere['id'] = 1;
            $totalNum->edit($editWhere,$array);
        }

        $where['id'] = 1;
        $rs = $totalNum->getOne($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

}
